module ReportsHelper

def pagination_links_remote(paginator)
  page_options = {:window_size => 1}
  pagination_links_each(paginator, page_options) do |n|
    options = {
      :url => {:action => 'new', :params => params.merge({:page => n, :from_page => true})},
      :update => 'table',
      :before => "Element.show('spinner')",
      :success => "Element.hide('spinner')"
    }
    html_options = {:href => url_for(:action => 'new', :params => params.merge({:page => n, :from_page => true}))}
    link_to_remote(n.to_s, options, html_options)
  end
end

def sort_td_class_helper(param)
  result = 'class="sortup"' if params[:sort] == param
  result = 'class="sortdown"' if params[:sort] == param + "_reverse"
  return result
end

def sort_link_helper(text, param)
  key = param
  key += "_reverse" if params[:sort] == param
  options = {
      :url => {:action => 'new', :params => params.merge({:sort => key, :page => nil, :from_sort => true })},
      :update => 'table',
      :before => "Element.show('spinner')",
      :success => "Element.hide('spinner')"
  }
  html_options = {
    :title => "Sort by this field",
    :href => url_for(:action => 'new', :params => params.merge({:sort => key, :page => nil, :from_sort => true }))
  }
  link_to_remote(text, options, html_options)
end

end
